<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-form ref="form" :model="manage_certificate" :rules="rules" label-width="100px" id="mvcfm">
      <div class="form-unit">
        <span class="mvc-title-left"> 搜索 </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
            <el-form-item label="产品名称" prop="apply_product_id">
              <el-select v-model="manage_certificate.apply_product_id" @change="list_cer_product">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in cer_product" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select> 型号 <el-select v-model="manage_certificate.model_id">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in s_index" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select> 规格 <el-select v-model="manage_certificate.norm_id">
                <el-option label="－－无－－" value='' />
                <el-option v-for="dict in s_index" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-button @click="searchCertificateSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>按产品搜索</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <div class="form-unit">
        <span class="mvc-title-left"> 关键件搜索 </span>
      </div>
      <el-table :data="s_index1">
        <el-table-column label="操作" prop="" width="100">
          <template slot-scope="scope">
            <el-link @click="appendRow(s_index1,scope)" type='primary'><i class='el-icon-plus' title='增加行' /></el-link>
            <el-link @click="delRow(s_index1,scope)" type='danger'><i class='el-icon-minus' title='删除行' /></el-link>
          </template>
        </el-table-column>
        <el-table-column label="关键件" prop="" style="width:100%;">
          <template slot-scope="scope">
            <el-input v-model="scope.row.part_name" placeholder='关键件' style="width:100%;" />
          </template>
        </el-table-column>
        <el-table-column label="型号" prop="" style="width:100%;">
          <template slot-scope="scope">
            <el-input v-model="scope.row.part_model" placeholder='型号' style="width:100%;" />
          </template>
        </el-table-column>
        <el-table-column label="规格" prop="" style="width:100%;">
          <template slot-scope="scope">
            <el-input v-model="scope.row.part_norm" placeholder='规格' style="width:100%;" />
          </template>
        </el-table-column>
        <el-table-column label="供应商" prop="" style="width:100%;">
          <template slot-scope="scope">
            <el-input v-model="scope.row.client_name" placeholder='供应商' style="width:100%;" />
          </template>
        </el-table-column>
      </el-table>
      <el-button @click="searchCertificateSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>按关键件搜索</el-button>
    </el-form>
  </div>
</template>
<script>
  import request from '@/utils/request'
  export default {
    name: 'SearchCertificate',
    components: {},
    props: ['popparams'],
    data() {
      return {
        vueparams: this.getVUEParams(""),
        manage_certificate: {
          apply_product_id: null,
          model_id: null,
          norm_id: null,
        },
        s_index1: [],
        cer_product: [],
        s_index: [],
        s_index: [],
        loading: false,
        rules: {}
      }
    },
    created() {
      this.getData();
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/searchCertificate?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      searchCertificateSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/mes/certificate/CertificateAction/searchCertificateSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/mes/certificate/SearchCertificateList/searchCertificateList?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      list_cer_product(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/mes/certificate/CertificateAction/ajaxCertificate?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "model_id,norm_id",
            apply_product_id: value
          }
        }).then(data => {
          this.$set(this.manage_certificate, 'model_id', '');
          this.s_index = data['model_id'];
          this.$set(this.manage_certificate, 'norm_id', '');
          this.s_index = data['norm_id'];
        })
      },
    },
  }
</script>
